import Config from '../config/index'

/*
* rem 屏幕适配
* 1. 整个屏幕宽度设置成750px
* 2. 使用 rem 作为单位, 1rem = 100px
* */
(function (doc, win) {
  const scale = Config.remScale
  const docEl = doc.documentElement
  const resizeEvt = 'onorientationchange' in window ? 'onorientationchange' : 'resize'
  const recalc = function () {
    var clientWidth = docEl.clientWidth
    if (!clientWidth) return
    if (clientWidth >= 750) {
      docEl.style.fontSize = `${scale}px`
    } else {
      docEl.style.fontSize = scale * (clientWidth / 750) + 'px'
    }
  }
  if (!doc.addEventListener) return
  win.addEventListener(resizeEvt, recalc, false)
  doc.addEventListener('DOMContentLoaded', recalc, false)
})(document, window)
